<template>
  <!--     @ok="handleOk" -->
  <j-modal
    :title="title"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @cancel="handleCancel"
    cancelText="关闭"
    :okButtonProps="{ style: { display: 'none' } }"
    destroyOnClose
  >
    <!-- <a-button style="margin:10px 0" type="primary" @click="$envet = serverCoach($envet)"> 绑定服务</a-button> -->
    <a-spin :spinning="confirmLoading">
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="avatarUrl" slot-scope="text, record">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.avatarUrl)" />
          </div>
        </template>

        <template slot="xhdjServerCoachLinkId" slot-scope="text, record">
          <div class="anty-img-wrap">
            <a-icon :type="record.xhdjServerCoachLinkId ? 'check' : 'close'" />
          </div>
        </template>
        <template slot="action" slot-scope="text, record">
          <a-popconfirm
            title="确定删除吗?"
            @confirm="() => handleDelete(record.xhdjServerCoachLinkId)"
            v-if="record.xhdjServerCoachLinkId"
          >
            <a>删除</a>
          </a-popconfirm>
        </template>
      </a-table>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction, getFileAccessHttpUrl } from '@/api/manage'
import Area from '@/components/_util/Area'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import moment from 'moment'
export default {
  name: 'XhdjCoachInfoDialog',
  mixins: [JeecgListMixin],
  data () {
    return {
      title: '操作',
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      isorter: {
        column: 'create_time',
        order: 'desc'
      },
      coachId: '',
      paramsDate: {},
      columns: [
        {
          title: '用户编号',
          dataIndex: 'id',
          width: 60,
          align: 'center'
        },

        {
          title: '头像',
          align: 'center',
          dataIndex: 'avatarUrl',
          scopedSlots: { customRender: 'avatarUrl' }
        },
        {
          title: '昵称',
          align: 'center',
          dataIndex: 'nickName'
        },

        {
          title: '手机号',
          align: 'center',
          dataIndex: 'phone'
        },
        {
          title: '支付笔数',
          align: 'center',
          dataIndex: 'xdCount'
        },
        {
          title: '消费金额',
          align: 'center',
          dataIndex: 'xdTotalAmount'
        },
        {
          title: '充值金额',
          align: 'center',
          dataIndex: 'topAmount'
        },
        // {
        //   // (0-默认未知,1-男,2-女)
        //   title: '性别',
        //   align: 'center',
        //   dataIndex: 'sex',
        //   customRender: (text, record) => {
        //     return record.sex == 1 ? '男' : record.sex == 2 ? '女' : '未知'
        //   },
        // },
        {
          title: '注册时间',
          align: 'center',
          dataIndex: 'createTime'
        }
      ],
      confirmLoading: false,
      dataSource: [],
      validatorRules: {},
      url: {
        list: '/xhdjUserInfo/list',
        add: '/xhdjServerCoachLink/add',
        delete: 'xhdjServerCoachLink/delete'
      },
      all: [], // 地址信息
      allList: [], // 省份数据
      citys: [],
      cityss: []
    }
  },
  created () {
    this.all = new Area().all
    this.allList = this.all.filter(res => res.index == 1)
  },
  methods: {
    uploadAction () {
      return window._CONFIG['domianURL'] + this.url.upload
    },
    getAvatarView: function (avatar) {
      return getFileAccessHttpUrl(avatar)
    },
    add () {
      //初始化默认值
      this.edit({})
    },
    onSelectChange (selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
      this.paramsDate = {
        coachId: this.coachId,
        serverIds: selectedRowKeys
      }
    },
    getCheckboxProps (record) {
      return {
        props: {
          disabled: record.xhdjServerCoachLinkId != null
        }
      }
    },
    edit (record) {
      console.log(record, '7777')
      this.queryParam.coachId = record
      this.loadData()
      this.visible = true
    },
    close () {
      this.$emit('close')
      this.selectedRowKeys = []
      this.selectionRows = []
      this.queryParam.coachId = ''
      this.visible = false
    },
    // 批量操作
    serverCoach () {
      if (this.paramsDate.serverIds && this.paramsDate.serverIds.length > 0) {
        console.log(this.paramsDate)
        httpAction(this.url.add, this.paramsDate, 'post')
          .then(res => {
            if (res.success) {
              this.$message.success(res.message)
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.confirmLoading = false
            this.close()
          })
      } else {
        this.$message.error('请选择需要绑定的服务')
      }
    },

    handleCancel () {
      this.close()
    }
  }
}
</script>

<style lang="less" scoped></style>
